package crypto.main;

import crypto.process.*;

import crypto.reference.References;
import crypto.util.FileManager;

/**
 * DOCUMENT ME!
 *
 * @author gato
 */
public class Crypto {

  private Matrix           matrix      = new Matrix();
  private CompleteBlock    complete    = new CompleteBlock();
  private DeleteEmptySpace delete      = new DeleteEmptySpace();
  private Sustitution      sustitution = new Sustitution();

  /**
   * DOCUMENT ME!
   *
   * @param text DOCUMENT ME!
   *
   * @return DOCUMENT ME!
   */
  public String encrypt(String text) {
    text   = matrix.mapBitsMayus(text);
    text   = complete.block(text);
    text   = delete.supressEmpty(text, complete.getOriginalSize(), complete.getBlocks());
    text   = sustitution.addCharacter(text);

    return text;
  }

  /**
   * DOCUMENT ME!
   *
   * @param text DOCUMENT ME!
   * @param fileName DOCUMENT ME!
   *
   * @return DOCUMENT ME!
   */
  public String encrypt(String text, String fileName) {
    text   = matrix.mapBitsMayus(text);
    text   = complete.block(text);
    //text   = delete.supressEmpty(text, complete.getOriginalSize(), complete.getBlocks());
    //text   = sustitution.addCharacter(text);
    
    References reference = new References( matrix, complete, delete, sustitution );
    text = reference.hideKeysInText(text);
    
    FileManager.saveFile(text, fileName);
    FileManager.saveFile(reference.getStringReference(), fileName+"Ref");

    return text;
  }
}
